package com.gccloud.design.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.gccloud.design.dao.*;
import com.gccloud.design.dto.SearchMyBusiness;
import com.gccloud.design.dto.UcBusiShowDto;
import com.gccloud.design.dto.UserAndRoleBusiOrderConfigDto;
import com.gccloud.design.entity.*;
import com.gccloud.design.feign.BaseCenterClient;
import com.gccloud.design.feign.SysRoleGroupClient;
import com.gccloud.design.feign.UserCenterClient;
import com.gccloud.design.service.UcBusiOrderShowService;
import com.gccloud.design.vo.SequenceVo;
import com.gccloud.design.vo.UserAndRoleBusiOrderConfigVo;
import com.gccloud.starter.common.exception.GlobalException;
import com.gccloud.starter.common.vo.R;
import com.gccloud.starter.core.vo.UserOrgInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author guo.wang
 */
@Service
public class UcBusiOrderShowServiceImpl implements UcBusiOrderShowService {

    private static final Logger LOGGER = LoggerFactory.getLogger(UcBusiOrderShowServiceImpl.class);

    @Resource
    private UcBusiShowDao ucBusiShowDao;
    @Resource
    private UcUserBusiOrderDao ucUserBusiOrderDao;
    @Resource
    private UcRoleBusiOrderDao ucRoleBusiOrderDao;
    @Resource
    private UcStationBusiOrderDao ucStationBusiOrderDao;

    @Resource
    private UserCenterClient userCenterClient;
    @Resource
    private BaseCenterClient baseCenterClient;
    @Resource
    private SdFormDefineDao sdFormDefineDao;
    @Resource
    private SysRoleGroupClient sysRoleGroupClient;


    @Override
    public Boolean userAndRoleBusiOrderConfig(UserAndRoleBusiOrderConfigDto userAndRoleBusiOrderConfigDto) {
        SdFormDefineEntity sd = userAndRoleBusiOrderConfigDto.getSdFormDefineEntityList().get(0);
        List<UcRoleBusiOrderEntity> ucRoleBusiOrderEntityList = userAndRoleBusiOrderConfigDto.getUcRoleBusiOrderEntityList();
        List<UcUserBusiOrderEntity> ucUserBusiOrderEntityList = userAndRoleBusiOrderConfigDto.getUcUserBusiOrderEntityList();
        // 把角色下人员 工位下人员放入set
        Set<UcUserBusiOrderEntity> set = new HashSet<>();
        //将人员放入set
        for (UcUserBusiOrderEntity uu : ucUserBusiOrderEntityList) {
            UcUserBusiOrderEntity ucUserBusiOrderEntity = new UcUserBusiOrderEntity();
            ucUserBusiOrderEntity.setUserName(uu.getUserName());
            ucUserBusiOrderEntity.setRealName(uu.getRealName());
            set.add(ucUserBusiOrderEntity);
        }
        //获取角色下的人员放入set
        R<List<UserOrgInfoVO>> resultClient2;
        for (UcRoleBusiOrderEntity ur : ucRoleBusiOrderEntityList) {
            try {
                resultClient2 =sysRoleGroupClient.getUserOrgInfoByRoleGroup(String.valueOf(ur.getRoleId()));
            } catch (Exception e) {
                LOGGER.info("查询角色下人员失败");
                throw new GlobalException("查询角色下人员失败", 500);
            }
            findUserListByRoleId(set, resultClient2);
        }
        int result = 0;
        Long formId = sd.getFormId();
        String formCode = sd.getFormCode();
        String formName = sd.getFormName();
        String catalogCode = sd.getCatalogCode();
        Integer catalogId = sd.getCatalogId();
        String catalogName = sd.getCatalogName();
        String formUrl = sd.getFormUrl();
        // 插入角色场景配置表
        for (UcRoleBusiOrderEntity ur : ucRoleBusiOrderEntityList) {
            Long roleId = ur.getRoleId();
            String code = ur.getCode();
            String name = ur.getName();
            // 查询表里是否存在
            QueryWrapper<UcRoleBusiOrderEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("role_id", ur.getRoleId()).eq("form_id", formId);
            if (ucRoleBusiOrderDao.selectCount(wrapper) == 0) {
                UcRoleBusiOrderEntity ucRoleBusiOrderEntity = new UcRoleBusiOrderEntity();
                ucRoleBusiOrderEntity.setRoleId(roleId).setCode(code).setName(name).setFormId(formId).setFormCode(formCode).setFormName(formName);
                ucRoleBusiOrderEntity.setShardingId(0);
                ucRoleBusiOrderDao.insert(ucRoleBusiOrderEntity);
            }
        }
        // 将set插入场景配置表
        for (UcUserBusiOrderEntity uu : set) {
            String userName = uu.getUserName();
            String realName = uu.getRealName();
            // 查询表里是否存在，插入用户场景配置表
            QueryWrapper<UcUserBusiOrderEntity> wrapper1 = new QueryWrapper<>();
            wrapper1.eq("user_name", uu.getUserName()).eq("form_id", formId);
            if (ucUserBusiOrderDao.selectCount(wrapper1) == 0) {
                UcUserBusiOrderEntity ucUserBusiOrderEntity = new UcUserBusiOrderEntity();
                ucUserBusiOrderEntity.setFormId(formId).setFormCode(formCode).setFormName(formName);
                ucUserBusiOrderEntity.setUserName(userName).setRealName(realName);
                ucUserBusiOrderEntity.setShardingId(0);
                ucUserBusiOrderDao.insert(ucUserBusiOrderEntity);
            }
            // 查询表里是否存在，存入场景展示表
            QueryWrapper<UcBusiShowEntity> wrapper = new QueryWrapper<>();
            wrapper.eq("user_name", uu.getUserName()).eq("form_id", formId);
            if (ucBusiShowDao.selectCount(wrapper) == 0) {
                UcBusiShowEntity ucBusiShowEntity = new UcBusiShowEntity();
                ucBusiShowEntity.setCatalogId(catalogId).setCatalogCode(catalogCode).setCatalogName(catalogName)
                        .setFormId(formId).setFormCode(formCode).setFormName(formName);
                ucBusiShowEntity.setShardingId(0).setOrderRemark("").setStatus(0).setSequence(0).setIconName("png1").setColor("#FACD91");
                if ("".equals(catalogCode)) {
                    ucBusiShowEntity.setCatalogCode("0");
                }
                ucBusiShowEntity.setRealName(realName)
                        .setUserName(userName)
                        .setUserName(userName)
                        .setRealName(realName)
                        .setFormUrl(formUrl)
                        .setParentId(sd.getParentId())
                        .setParentName(sd.getParentName());
                result = ucBusiShowDao.insert(ucBusiShowEntity);
            }
        }
        return result > 0;
    }

    private void findUserListByRoleId(Set<UcUserBusiOrderEntity> set, R<List<UserOrgInfoVO>> resultClient2) {
        List<UserOrgInfoVO> data = resultClient2.getData();
        for (UserOrgInfoVO user : data) {
            UcUserBusiOrderEntity ucUserBusiOrderEntity = new UcUserBusiOrderEntity();
            ucUserBusiOrderEntity.setUserName(user.getUserName());
            ucUserBusiOrderEntity.setRealName(user.getRealName());
            set.add(ucUserBusiOrderEntity);
        }
    }

    private void findUserListByStationId(Set<UcUserBusiOrderEntity> set, R<List<Map<String, Object>>> resultClient) {
        List<Map<String, Object>> data = resultClient.getData();
        for (Map<String, Object> map2 : data) {
            UcUserBusiOrderEntity ucUserBusiOrderEntity = new UcUserBusiOrderEntity();
            ucUserBusiOrderEntity.setUserName((String) map2.get("userId"));
            ucUserBusiOrderEntity.setRealName((String) map2.get("userName"));
            set.add(ucUserBusiOrderEntity);
        }
    }

    @Override
    public UserAndRoleBusiOrderConfigVo findUserAndRoleOrderConfig(String[] formIds) {
        // 查询用户set
        QueryWrapper<UcUserBusiOrderEntity> wrapper = new QueryWrapper<>();
        wrapper.in("form_id", (Object[]) formIds);
        List<UcUserBusiOrderEntity> ucUserBusiOrderEntities = ucUserBusiOrderDao.selectList(wrapper);
        Set<UcUserBusiOrderEntity> set1 = new HashSet<>();
        Set<UcRoleBusiOrderEntity> set2 = new HashSet<>();
        Set<UcStationBusiOrderEntity> set3 = new HashSet<>();
        for (UcUserBusiOrderEntity uu : ucUserBusiOrderEntities) {
            UcUserBusiOrderEntity ucUserBusiOrderEntity = new UcUserBusiOrderEntity();
            ucUserBusiOrderEntity.setUserName(uu.getUserName());
            ucUserBusiOrderEntity.setRealName(uu.getRealName());
            set1.add(ucUserBusiOrderEntity);
        }
        // 角色表下的人员查询
        QueryWrapper<UcRoleBusiOrderEntity> wrapper1 = new QueryWrapper<>();
        wrapper1.in("form_id", (Object[]) formIds);
        List<UcRoleBusiOrderEntity> ucRoleBusiOrderEntityList = ucRoleBusiOrderDao.selectList(wrapper1);
        if (ucRoleBusiOrderEntityList.size() > 0) {
            for (UcRoleBusiOrderEntity ur : ucRoleBusiOrderEntityList) {
                // 把角色放进set2
                UcRoleBusiOrderEntity ucRoleBusiOrderEntity = new UcRoleBusiOrderEntity();
                ucRoleBusiOrderEntity.setRoleId(ur.getRoleId());
                ucRoleBusiOrderEntity.setName(ur.getName());
                ucRoleBusiOrderEntity.setCode(ur.getCode());
                set2.add(ucRoleBusiOrderEntity);
                R<List<UserOrgInfoVO>>  resultClient;
                try {
                    resultClient =sysRoleGroupClient.getUserOrgInfoByRoleGroup(String.valueOf(ur.getRoleId()));
                } catch (Exception e) {
                    LOGGER.info("查询角色下人员失败");
                    throw new GlobalException("查询角色下人员失败", 500);
                }
                findUserListByRoleId(set1, resultClient);
            }
        }
        // 工位表下的人员查询
        QueryWrapper<UcStationBusiOrderEntity> wrapper2 = new QueryWrapper<>();
        wrapper1.in("form_id", (Object[]) formIds);
        List<UcStationBusiOrderEntity> ucStationBusiOrderEntityList = ucStationBusiOrderDao.selectList(wrapper2);
        if (ucStationBusiOrderEntityList.size() > 0) {
            for (UcStationBusiOrderEntity ur : ucStationBusiOrderEntityList) {
                // 把工位放进set3
                UcStationBusiOrderEntity ucStationBusiOrderEntity = new UcStationBusiOrderEntity();
                ucStationBusiOrderEntity.setStationId(ur.getStationId());
                ucStationBusiOrderEntity.setStationName(ur.getStationName());
                ucStationBusiOrderEntity.setStationType(ur.getStationType());
                set3.add(ucStationBusiOrderEntity);
                R<List<Map<String, Object>>> resultClient;
                try {
                    resultClient = baseCenterClient.getStationUserConf(ur.getStationId());
                } catch (Exception e) {
                    LOGGER.info("查询工位下人员失败");
                    throw new GlobalException("查询工位下人员失败", 500);
                }
                findUserListByStationId(set1, resultClient);
            }
        }
        // 查询有哪些角色和工位下新建的用户没保存
        Set<UcUserBusiOrderEntity> set4 = new HashSet<>();
        for (UcUserBusiOrderEntity uu : set1) {
            String userName = uu.getUserName();
            QueryWrapper<UcUserBusiOrderEntity> wrapper3 = new QueryWrapper<>();
            wrapper3.eq("form_id", formIds[0]).eq("user_name", userName);
            if (ucUserBusiOrderDao.selectCount(wrapper3) == 0) {
                set4.add(uu);
            }
        }
        // 放入vo
        UserAndRoleBusiOrderConfigVo userAndRoleBusiOrderConfigVo = new UserAndRoleBusiOrderConfigVo();
        userAndRoleBusiOrderConfigVo.setUcUserBusiOrderEntitySet(set1)
                .setUcRoleBusiOrderEntitySet(set2)
                .setUcStationBusiOrderEntitySet(set3)
                .setUcUserBusiOrderEntitySetNew(set4);
        return userAndRoleBusiOrderConfigVo;
    }

    @Override
    public List<UcBusiShowEntity> getMyOrderList(SearchMyBusiness searchMyBusiness) {
        QueryWrapper<UcBusiShowEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name", searchMyBusiness.getUserName()).eq("status", 0).orderByAsc("sequence");
        if (!"".equals(searchMyBusiness.getCatalogName()) && searchMyBusiness.getCatalogName() != null) {
            wrapper.like("catalog_name", searchMyBusiness.getCatalogName());
        }
        return ucBusiShowDao.selectList(wrapper);
    }

    @Override
    public List<UcBusiShowEntity> getMyOrderListByIds(Map<String, String> map) {
        return ucBusiShowDao.getMyOrderListByIds(map.get("ids"));
    }

    @Override
    public List<UcBusiShowDto> getBusiTree(Map<String, String> map) {
        List<UcBusiShowDto> list;
        String orderTypeId = map.get("orderTypeId");
        if ("".equals(orderTypeId)) {
            list = ucBusiShowDao.getParent(map.get("userName"),map.get("spec"));
            // 判断是否网信安发单
            if (map.get("orderSpecId") != null && list.size() > 0) {
                UcBusiShowDto ucBusiShowDto = new UcBusiShowDto();
                for (UcBusiShowDto dto : list) {
                    if (dto.getParentId().toString().equals(map.get("orderSpecId"))) {
                        ucBusiShowDto = dto;
                        break;
                    }
                }
                list.clear();
                if (!StringUtils.isEmpty(ucBusiShowDto.getParentName())) {
                    list.add(ucBusiShowDto);
                }
            }
            if (list.size() > 0) {
                for (UcBusiShowDto dto : list) {
                    List<UcBusiShowDto> ucBusiShowDtos = ucBusiShowDao.getBusiTree(map.get("userName"), dto.getParentId());
                    dto.setChild(ucBusiShowDtos);
                }
            }
        } else {
            list = ucBusiShowDao.getBusiByOrderTypeId(map.get("userName"), orderTypeId);
        }
        return list;
    }

    @Override
    public Boolean updateMyOrder(UcBusiShowEntity ucBusiShowEntity) {
        int result = 0;
        if (ucBusiShowEntity != null) {
            result = ucBusiShowDao.updateById(ucBusiShowEntity);
        }
        return result > 0;
    }

    @Override
    public Boolean updateMyOrderSequence(List<UcBusiShowEntity> ucBusiShowEntity) {
        int result = 0;
        if (ucBusiShowEntity != null) {
            for (UcBusiShowEntity ub : ucBusiShowEntity) {
                result = ucBusiShowDao.updateById(ub);
            }
        }
        return result > 0;
    }

    @Override
    public Boolean updateMyOrderByFormId(UcBusiShowEntity ucBusiShowEntity) {
        int result = 0;
        List<UcBusiShowEntity> ucBusiShowEntities = findBusiShowByFormId(ucBusiShowEntity);
        for (UcBusiShowEntity uc : ucBusiShowEntities) {
            UpdateWrapper<UcBusiShowEntity> wrapper = new UpdateWrapper<>();
            wrapper.eq("form_id", ucBusiShowEntity.getFormId());
            wrapper.eq("user_name", uc.getUserName());
            wrapper.set("color", ucBusiShowEntity.getColor());
            wrapper.set("sequence", ucBusiShowEntity.getSequence());
            wrapper.set("status", ucBusiShowEntity.getStatus());
            wrapper.set("icon_name", ucBusiShowEntity.getIconName());
            wrapper.set("order_remark", ucBusiShowEntity.getOrderRemark());
            result = ucBusiShowDao.update(uc, wrapper);
        }
        return result > 0;
    }

    @Override
    public List<UcBusiShowEntity> getMyOrderByFormId(UcBusiShowEntity ucBusiShowEntity) {
        List<UcBusiShowEntity> ucBusiShowEntities = findBusiShowByFormId(ucBusiShowEntity);
        for (UcBusiShowEntity ub : ucBusiShowEntities) {
            Long formId = ub.getFormId();
            SdFormDefineEntity sdFormDefineEntity = sdFormDefineDao.selectById(formId);
            ub.setFormUrl(sdFormDefineEntity.getFormUrl());
        }
        return ucBusiShowEntities;
    }

    private List<UcBusiShowEntity> findBusiShowByFormId(UcBusiShowEntity ucBusiShowEntity) {
        QueryWrapper<UcBusiShowEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("form_id", ucBusiShowEntity.getFormId());
        if (!"".equals(ucBusiShowEntity.getUserName()) && ucBusiShowEntity.getUserName() != null) {
            wrapper.eq("user_name", ucBusiShowEntity.getUserName());
        }
        return ucBusiShowDao.selectList(wrapper);
    }

    @Override
    public Boolean delMyOrderByFormId(UserAndRoleBusiOrderConfigDto userAndRoleBusiOrderConfigDto) {
        Long formId = userAndRoleBusiOrderConfigDto.getSdFormDefineEntityList().get(0).getFormId();
        List<UcRoleBusiOrderEntity> ucRoleBusiOrderEntityList = userAndRoleBusiOrderConfigDto.getUcRoleBusiOrderEntityList();
        List<UcUserBusiOrderEntity> ucUserBusiOrderEntityList = userAndRoleBusiOrderConfigDto.getUcUserBusiOrderEntityList();
        List<UcStationBusiOrderEntity> ucStationBusiOrderEntityList = userAndRoleBusiOrderConfigDto.getUcStationBusiOrderEntityList();
        int del1 = 0, del2 = 0, del3 = 0;
        // 删除角色 和角色下人员
        if (ucRoleBusiOrderEntityList != null && ucRoleBusiOrderEntityList.size() > 0) {
            for (UcRoleBusiOrderEntity ur : ucRoleBusiOrderEntityList) {
                Long roleId = ur.getRoleId();
                // 查询数据库存在该角色吗
                QueryWrapper<UcRoleBusiOrderEntity> wrapper1 = new QueryWrapper<>();
                if (ucRoleBusiOrderDao.selectCount(wrapper1.eq("form_id", formId).eq("role_id", roleId)) > 0) {
                    R<List<Map<String, Object>>> userOrgInfoByRole;
                    try {
                        userOrgInfoByRole = userCenterClient.getUserOrgInfoByRole(roleId);
                    } catch (Exception e) {
                        LOGGER.info("查询角色下人员失败");
                        throw new GlobalException("查询角色下人员失败", 500);
                    }
                    List<Map<String, Object>> data = userOrgInfoByRole.getData();
                    for (Map<String, Object> map : data) {
                        String userName = (String) map.get("userName");
                        // 删除用户表
                        delUserAndShow(formId, userName);
                    }
                    QueryWrapper<UcRoleBusiOrderEntity> wrapper = new QueryWrapper<>();
                    wrapper.eq("form_id", formId).eq("role_id", roleId);
                    del1 = ucRoleBusiOrderDao.delete(wrapper);
                } else {
                    del1 = 1;
                }
            }
        }
        // 删除用户 检测角色和工位下有无该用户 若有 不给删除
        if (ucUserBusiOrderEntityList != null && ucUserBusiOrderEntityList.size() > 0) {
            for (UcUserBusiOrderEntity uc : ucUserBusiOrderEntityList) {
                String user = uc.getUserName();
                // 查询数据库存在该角色吗
                QueryWrapper<UcUserBusiOrderEntity> wrapper4 = new QueryWrapper<>();
                if (ucUserBusiOrderDao.selectCount(wrapper4.eq("form_id", formId).eq("user_name", user)) > 0) {
                    // 检测角色下的用户
                    QueryWrapper<UcRoleBusiOrderEntity> wrapper2 = new QueryWrapper<>();
                    wrapper2.eq("form_id", formId);
                    List<UcRoleBusiOrderEntity> ucRoleBusiOrderEntityList1 = ucRoleBusiOrderDao.selectList(wrapper2);
                    for (UcRoleBusiOrderEntity ur : ucRoleBusiOrderEntityList1) {
                        R<List<Map<String, Object>>> userOrgInfoByRole;
                        try {
                            userOrgInfoByRole = userCenterClient.getUserOrgInfoByRole(ur.getRoleId());
                        } catch (Exception e) {
                            LOGGER.info("查询角色下人员失败");
                            throw new GlobalException("查询角色下人员失败", 500);
                        }
                        List<Map<String, Object>> data = userOrgInfoByRole.getData();
                        // 检测data中的userName 与ur里的userName是否相同 相同不给删除
                        for (Map<String, Object> map : data) {
                            String userName = (String) map.get("userName");
                            if (userName.equals(user)) {
                                // 有相同的不给删除
                                LOGGER.info("删除的用户在角色下存在，请先删除角色或者取消角色人员关系");
                                LOGGER.info("角色名称是：" + ur.getName() + ",角色ID：" + ur.getRoleId());
                                throw new GlobalException("删除的用户在角色下存在，请先删除角色或者取消角色人员关系", 500);
                            }
                        }
                    }
                    // 检测工位下的用户
                    QueryWrapper<UcStationBusiOrderEntity> wrapper3 = new QueryWrapper<>();
                    wrapper3.eq("form_id", formId);
                    List<UcStationBusiOrderEntity> ucStationBusiOrderEntityList1 = ucStationBusiOrderDao.selectList(wrapper3);
                    for (UcStationBusiOrderEntity us : ucStationBusiOrderEntityList1) {
                        R<List<Map<String, Object>>> stationUserConf;
                        try {
                            stationUserConf = baseCenterClient.getStationUserConf(us.getStationId());
                        } catch (Exception e) {
                            LOGGER.info("查询工位下人员失败");
                            throw new GlobalException("查询工位下人员失败", 500);
                        }
                        List<Map<String, Object>> data = stationUserConf.getData();
                        // 检测data中的userName 与ur里的userName是否相同 相同不给删除
                        for (Map<String, Object> map : data) {
                            String userName = (String) map.get("userId");
                            if (userName.equals(user)) {
                                // 有相同的不给删除
                                LOGGER.info("删除的用户在工位下存在，请先删除工位或者取消工位人员关系");
                                LOGGER.info("工位名称是：" + us.getStationName() + ",工位ID：" + us.getStationId());
                                throw new GlobalException("删除的用户在工位下存在，请先删除工位或者取消工位人员关系", 500);
                            }
                        }
                    }
                    // 删除用户表
                    QueryWrapper<UcUserBusiOrderEntity> wrapper = new QueryWrapper<>();
                    wrapper.eq("form_id", formId).eq("user_name", user);
                    del2 = ucUserBusiOrderDao.delete(wrapper);
                    // 删除个性化表
                    QueryWrapper<UcBusiShowEntity> wrapper1 = new QueryWrapper<>();
                    wrapper1.eq("form_id", formId).eq("user_name", user);
                    ucBusiShowDao.delete(wrapper1);
                } else {
                    del2 = 1;
                }

            }
        }
        // 删除工位 和工位下人员
        if (ucStationBusiOrderEntityList != null && ucStationBusiOrderEntityList.size() > 0) {
            for (UcStationBusiOrderEntity ur : ucStationBusiOrderEntityList) {
                Long stationId = ur.getStationId();
                // 查询数据库存在该角色吗
                QueryWrapper<UcStationBusiOrderEntity> wrapper1 = new QueryWrapper<>();
                if (ucStationBusiOrderDao.selectCount(wrapper1.eq("form_id", formId).eq("station_id", stationId)) > 0) {
                    // 查到工位下人员 删除
                    R<List<Map<String, Object>>> stationUserConf;
                    try {
                        stationUserConf = baseCenterClient.getStationUserConf(stationId);
                    } catch (Exception e) {
                        LOGGER.info("查询工位下人员失败");
                        throw new GlobalException("查询工位下人员失败", 500);
                    }
                    List<Map<String, Object>> data = stationUserConf.getData();
                    for (Map<String, Object> map : data) {
                        String userId = (String) map.get("userId");
                        // 删除用户表
                        delUserAndShow(formId, userId);
                    }
                    // 删除工位
                    QueryWrapper<UcStationBusiOrderEntity> wrapper = new QueryWrapper<>();
                    wrapper.eq("form_id", formId).eq("station_id", stationId);
                    del3 = ucStationBusiOrderDao.delete(wrapper);
                } else {
                    del3 = 1;
                }
            }
        }
        return del1 > 0 || del2 > 0 || del3 > 0;
    }

    private void delUserAndShow(Long formId, String userName) {
        QueryWrapper<UcUserBusiOrderEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("form_id", formId).eq("user_name", userName);
        ucUserBusiOrderDao.delete(wrapper);
        QueryWrapper<UcBusiShowEntity> wrapper1 = new QueryWrapper<>();
        wrapper1.eq("form_id", formId).eq("user_name", userName);
        ucBusiShowDao.delete(wrapper1);
    }

    @Override
    public SdFormDefineEntity getFormUrlByFormId(Long formId) {
        return sdFormDefineDao.selectById(formId);
    }

    @Override
    public Long changeSequence(List<SequenceVo> sequenceVos) {
        return ucBusiShowDao.changeSequence(sequenceVos);
    }

    /**
     *
     * @param formIds
     * @return
     */
    @Override
    public int delByFormId(Long[] formIds) {
        QueryWrapper<UcBusiShowEntity> wrapper = new QueryWrapper<>();
        wrapper.in("FORM_ID", formIds);
        return  ucBusiShowDao.delete(wrapper);
    }
}
